package com.rd.util;




import java.util.HashMap;
import java.util.Map;

/**
 * 页面响应的数据(自定义返回json数据)

 */
public class ResultModel extends HashMap<String, Object> {

    @Override
    public ResultModel put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public ResultModel() {
    }

    public static ResultModel createBySuccess() {
        ResultModel rm = new ResultModel();
        rm.put("code", ResponseCode.SUCCESS.getCode());
        rm.put("desc",ResponseCode.SUCCESS.getDesc());
        return rm;
    }

    public static ResultModel createBySuccess(String msg) {
        ResultModel rm = new ResultModel();
        rm.put("code", ResponseCode.SUCCESS.getCode());
        rm.put("desc",ResponseCode.SUCCESS.getDesc());
        rm.put("msg",msg);
        return rm;
    }

    public static ResultModel createBySuccess(String key,Object value) {
        ResultModel rm = new ResultModel();
        rm.put("code", ResponseCode.SUCCESS.getCode());
        rm.put("desc",ResponseCode.SUCCESS.getDesc());
        //数据  data:数据
        //     token:数据  userList:数据
        rm.put(key,value);
        return rm;
    }

    public static ResultModel createBySuccess(Map<String, Object> map) {
        ResultModel rm = new ResultModel();
        rm.put("code", ResponseCode.SUCCESS.getCode());
        rm.put("desc",ResponseCode.SUCCESS.getDesc());
        rm.putAll(map);
        return rm;
    }

    public static ResultModel createByErrorCodeMessage() {
        ResultModel rm=new ResultModel();
        rm.put("code", ResponseCode.ERROR.getCode());
        rm.put("desc",ResponseCode.ERROR.getDesc());
        rm.put("msg","后台服务器错误,请联系管理员,检查后台代码!");
        return rm;
    }

    public static ResultModel createByErrorCodeMessage(String msg) {
        ResultModel rm=new ResultModel();
        rm.put("code", ResponseCode.ERROR.getCode());
        rm.put("desc",ResponseCode.ERROR.getDesc());
        rm.put("msg",msg);
        return rm;
    }

    public static ResultModel createByErrorCodeMessage(ResponseCode responseCode, String msg) {
        ResultModel rm = new ResultModel();
        rm.put("code", responseCode.getCode());
        rm.put("desc",responseCode.getDesc());
        rm.put("msg",msg);
        return rm;
    }
    public static ResultModel createByErrorCodeMessage(int code, String msg) {
        ResultModel rm = new ResultModel();
        rm.put("code", code);
        rm.put("msg",msg);
        return rm;
    }
    public static ResultModel createByErrorCodeMessage(int code, String desc, String msg) {
        ResultModel rm = new ResultModel();
        rm.put("code", code);
        rm.put("desc",desc);
        rm.put("msg",msg);
        return rm;
    }


}
